package com.portal.controller;

import com.portal.common.Result;
import com.portal.entity.Case;
import com.portal.service.CaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@Api(tags = "客户案例接口")
@RestController
@RequestMapping("/cases")
public class CaseController {
    
    @Autowired
    private CaseService caseService;
    
    /**
     * 获取案例列表
     */
    @ApiOperation("获取案例列表")
    @GetMapping("/list")
    public Result<Map<String, Object>> getCaseList(
            @RequestParam(required = false) Long categoryId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        try {
            Map<String, Object> result = caseService.getCaseList(categoryId, page, size);
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取案例列表失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取案例详情
     */
    @ApiOperation("获取案例详情")
    @GetMapping("/{id}")
    public Result<Case> getCaseDetail(@PathVariable Long id) {
        try {
            Case cases = caseService.getCaseDetail(id);
            if (cases == null) {
                return Result.error("案例不存在");
            }
            return Result.success(cases);
        } catch (Exception e) {
            return Result.error("获取案例详情失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取推荐案例列表
     */
    @ApiOperation("获取推荐案例列表")
    @GetMapping("/recommend")
    public Result<List<Case>> getRecommendCases(@RequestParam(defaultValue = "6") int limit) {
        try {
            List<Case> list = caseService.getRecommendCases(limit);
            return Result.success(list);
        } catch (Exception e) {
            return Result.error("获取推荐案例失败：" + e.getMessage());
        }
    }

    /**
     * 获取客户案例列表
     */
    @ApiOperation("获取客户案例列表")
    @GetMapping("/customers")
    public Result<List<Case>> getCustomerCases() {
        try {
            List<Case> list = caseService.getCustomerCases();
            return Result.success(list);
        } catch (Exception e) {
            return Result.error("获取客户案例失败：" + e.getMessage());
        }
    }

    /**
     * 获取案例分类
     */
    @ApiOperation("获取案例分类")
    @GetMapping("/categories")
    public Result<List<String>> getCaseCategories() {
        try {
            List<String> categories = caseService.getCaseCategories();
            return Result.success(categories);
        } catch (Exception e) {
            return Result.error("获取案例分类失败：" + e.getMessage());
        }
    }
} 